package core;

import static org.junit.Assert.*;

import org.junit.Test;

public class AmountTests {

	@Test
	public void correctSizeTest()
	{
		Unit u = Unit.fluidOunces;
		Amount amt = new Amount(u,11.9f);
		
		boolean thrown = false;
		try{
			amt.setSize(-2.5f);
		}
		catch(IllegalArgumentException e)
		{
			thrown = true;
		}
		assertTrue(thrown);
	}
	
	@Test
	public void wholeNumberTest()
	{
		Unit u = Unit.ounces;
		Amount amt = new Amount(u,1.2f);
		boolean thrown = false;
		
		try{
			amt.setUnit(Unit.count);
		}
		catch(IllegalArgumentException e)
		{
			thrown = true;
		}
		assertTrue(thrown);
	}
	
	@Test
	public void amountConversionTest()
	{
		//Test values
		float poundsToOunces = 0.0f;
		float ouncesToGrams = 0.0f;
		float gramsToPounds = 0.0f;
		float kiloToGrams = 0.0f;
		
		try 
		{
			poundsToOunces = Amount.getConversionAmount(Unit.pounds, Unit.ounces);
			ouncesToGrams = Amount.getConversionAmount(Unit.ounces, Unit.grams);
			gramsToPounds = Amount.getConversionAmount(Unit.grams, Unit.pounds);
			kiloToGrams = Amount.getConversionAmount(Unit.kilograms, Unit.grams);
		} 
		catch (Exception e) 
		{
			System.out.println(e.getMessage());
		}
		
		assertTrue(poundsToOunces == 16.0f);
		assertTrue(ouncesToGrams == 28.3495f);
		assertTrue(gramsToPounds == 0.00220462f);
		assertTrue(kiloToGrams == 1000.0f);
	}
}
